package org.mapdroid.data.adt;

import java.util.Calendar;
import java.util.GregorianCalendar;

import android.os.Parcel;
import android.os.Parcelable;

public class Book implements Parcelable{
	private String clientId;
	private GregorianCalendar date;
	
	public Book(String clientId){
		this.clientId = clientId;
		//Initialize the calendar with the current date and time
		date = new GregorianCalendar();
	}
	
	public Book(String clientId, int year, int month, int day, int hour, int minutes, int seconds){
		this.clientId = clientId;
		//Initialize the calendar with the current date and time
		date = new GregorianCalendar(year, month, day, hour, minutes, seconds);
	}
	
	public Book(Parcel in){
		this.clientId = in.readString();
		
		int year = in.readInt();
		int month = in.readInt();
		int day = in.readInt();
		int hour = in.readInt();
		int minutes = in.readInt();
		int seconds = in.readInt();
		this.date = new GregorianCalendar(year, month, day, hour, minutes, seconds);
	}
	
	public String getPersonId(){
		return this.clientId;
	}
	
	public int getYear(){
		return this.date.get(Calendar.YEAR);
	}
	
	public int getMonth(){
		return this.date.get(Calendar.MONTH);
	}
	
	public int getDay(){
		return this.date.get(Calendar.DAY_OF_MONTH);
	}
	
	public int getHour(){
		return this.date.get(Calendar.HOUR_OF_DAY);
	}
	
	public int getMinute(){
		return this.date.get(Calendar.MINUTE);
	}
	
	public int getSecond(){
		return this.date.get(Calendar.SECOND);
	}

	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		// TODO Auto-generated method stub
		dest.writeString(this.clientId);
		dest.writeInt(getYear());
		dest.writeInt(getMonth());
		dest.writeInt(getDay());
		dest.writeInt(getHour());
		dest.writeInt(getMinute());
		dest.writeInt(getSecond());
	}
	
	public static final Parcelable.Creator<Book> CREATOR
			= new Parcelable.Creator<Book>() {
		public Book createFromParcel(Parcel in) {
			return new Book(in);
		}

		public Book[] newArray(int size) {
			return new Book[size];
		}
	};

	@Override
	public boolean equals(Object o){
		String username = ((Book) o).getPersonId();
		if(this.clientId.contentEquals(username))
			return true;
		return false;
	}
	
	@Override
	public String toString(){
		return String.format("%02d:%02d", this.getHour(), this.getMinute());
	}
}
